package com.example.scity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.scity.beens.HdglBannerBeen;
import com.example.scity.beens.MovieBeen;
import com.example.scity.beens.MzyyBannerBeen;
import com.example.scity.beens.WlcxBannerBeen;
import com.example.scity.beens.WlcxListBeen;
import com.example.scity.beens.WmdcBannerBeen;
import com.google.gson.Gson;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class WlcxActivity extends AppCompatActivity {
    ListView wlcxlistview;
    WlcxListBeen wlcxListBeen;
    Handler handler=new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 0:
                    WlcxListView();
                    break;
            }
        }
    };
    private void WlcxListView() {
        wlcxlistview.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return wlcxListBeen.data.size();
            }

            @Override
            public Object getItem(int i) {
                return wlcxListBeen.data.get(i);
            }

            @Override
            public long getItemId(int i) {
                return i;
            }

            @Override
            public View getView(int i, View view, ViewGroup viewGroup) {
                view = LayoutInflater.from(WlcxActivity.this).inflate(R.layout.item_wlcx, null);
                ImageView imageView;
                imageView = view.findViewById(R.id.wlcx_img);
                Glide.with(view).load(Configs.Host + wlcxListBeen.data.get(i).imgUrl).into(imageView);
                TextView name;
                name = view.findViewById(R.id.wlcxname);
                name.setText("名称:"+wlcxListBeen.data.get(i).name);
                TextView introduce;
                introduce = view.findViewById(R.id.wlcxintroduce);
                introduce.setText("介绍:"+wlcxListBeen.data.get(i).introduce);
                TextView shippingMethod;
                shippingMethod = view.findViewById(R.id.wlcxshippingMethod);
                shippingMethod.setText("运输方式:"+wlcxListBeen.data.get(i).shippingMethod);
                TextView phone;
                shippingMethod = view.findViewById(R.id.wlcxphone);
                shippingMethod.setText("运输方式:"+wlcxListBeen.data.get(i).phone);
                return view;
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wlcx);
        wlcxlistview=findViewById(R.id.wlcxlistview);
        LoadWlcxlist();
    }
    private void LoadWlcxlist() {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(Configs.Host + APIInterface.WLCXList)
                .get()
                .build();
        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {

            }

            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
                wlcxListBeen = new Gson().fromJson(response.body().string(), WlcxListBeen.class);
                handler.sendEmptyMessage(0);
            }
        });
    }
}